import 'package:flutter/material.dart';
import 'package:flutter_dwh5/pages/my/order/roundUnderlineTabIndicator.dart';

class Order extends StatefulWidget {
  @override
  State<Order> createState() => _OrderState();
}

class _OrderState extends State<Order> {
  List tabs = [
    {
      'name': '全部',
      'no': 'RH4564646456',
      'type': '0',
      'total': '1',
      'taotalPrice': '999',
      'data': [
        {
          'title': 'Do－win/多威定制款战神',
          'kuan': 'M911',
          "code": '40',
          'price': '99',
          'num': '1'
        },
        {
          'title': 'Do－win/多威定制款战神1',
          'kuan': 'M9112',
          "code": '43',
          'price': '992',
          'num': '3'
        }
      ]
    },
    {
      'name': '待付款',
      'no': 'RH4564646456',
      'type': '1',
      'total': '2',
      'taotalPrice': '1999',
      'data': [
        {
          'title': 'Do－win/多威定制款战神',
          'kuan': 'M911',
          "code": '40',
          'price': '100',
          'num': '1'
        }
      ]
    },
    {
      'name': '待发货',
      'no': 'RH4564646456',
      'type': '2',
      'total': '2',
      'taotalPrice': '1999',
      'data': [
        {
          'title': 'Do－win/多威定制款战神',
          'kuan': 'M911',
          "code": '40',
          'price': '100',
          'num': '1'
        }
      ]
    },
    {
      'name': '待收货',
      'no': 'RH4564646456',
      'type': '3',
      'total': '3',
      'taotalPrice': '2999',
      'data': [
        {
          'title': 'Do－win/多威定制款战神',
          'kuan': 'M911',
          "code": '40',
          'price': '101',
          'num': '1'
        }
      ]
    },
    {
      'name': '已完成',
      'no': 'RH4564646456',
      'type': '4',
      'total': '4',
      'taotalPrice': '3999',
      'data': [
        {
          'title': 'Do－win/多威定制款战神',
          'kuan': 'M911',
          "code": '40',
          'price': '102',
          'num': '1'
        }
      ]
    },
    {
      'name': '已取消',
      'no': 'RH4564646456',
      'type': '5',
      'total': '5',
      'taotalPrice': '4999',
      'data': [
        {
          'title': 'Do－win/多威定制款战神',
          'kuan': 'M911',
          "code": '40',
          'price': '103',
          'num': '1'
        }
      ]
    }
  ];

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: tabs.length,
        child: Scaffold(
          appBar: AppBar(
            title: Text('我的订单'),
            elevation: 0,
            bottom: TabBar(
              isScrollable: true,
              tabs: tabs
                  .map((item) => Tab(
                        text: item['name'],
                      ))
                  .toList(),
              indicatorColor: Colors.black,
              labelColor: Colors.black,
              indicatorSize: TabBarIndicatorSize.label,
              indicator: RoundUnderlineTabIndicator(
                  borderSide: BorderSide(width: 3.0, color: Colors.black)),
              onTap: (int i) {
                print(i);
              },
            ),
          ),
          body: TabBarView(
            children: tabs
                .map((item) => Container(
                      child: Column(
                        children: [
                          Container(
                            padding:
                                EdgeInsets.only(left: 10, right: 10, top: 10),
                            child: Row(
                              children: [
                                Container(
                                  margin: EdgeInsets.only(right: 5),
                                  child: Image.asset(
                                    'images/my/orderIcon.png',
                                    width: 12,
                                    height: 13,
                                    fit: BoxFit.cover,
                                  ),
                                ),
                                Expanded(
                                    child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Container(
                                      child: Text('订单编号：${item['no']}'),
                                    ),
                                    GestureDetector(
                                      onTap: () {},
                                      child: Container(
                                        child: Text(
                                          '${item['name']}',
                                          style: TextStyle(
                                              fontSize: 16,
                                              fontWeight: FontWeight.bold),
                                        ),
                                      ),
                                    )
                                  ],
                                ))
                              ],
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(top: 13),
                            child: Divider(
                              height: 0.3,
                            ),
                          ),
                          Column(
                              children: (item['data'] as List)
                                  .toList()
                                  .map((goods) => Container(
                                        padding: EdgeInsets.all(15),
                                        margin: EdgeInsets.only(top: 2.5),
                                        color: Colors.white,
                                        child: Row(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            Container(
                                              margin:
                                                  EdgeInsets.only(right: 10),
                                              child: Image.asset(
                                                'images/home/good.png',
                                                width: 76,
                                                height: 76,
                                                fit: BoxFit.cover,
                                              ),
                                            ),
                                            Expanded(
                                                child: Container(
                                              height: 76,
                                              child: Row(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.end,
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  Column(
                                                    crossAxisAlignment:
                                                        CrossAxisAlignment
                                                            .start,
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceBetween,
                                                    children: [
                                                      Column(
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .start,
                                                        children: [
                                                          Container(
                                                            child: Text(
                                                                '${goods['title']}'),
                                                          ),
                                                          Container(
                                                              child: Text(
                                                            '款号：${goods['kuan']},尺码${goods['code']}',
                                                            style: TextStyle(
                                                                fontSize: 10,
                                                                color: Color
                                                                    .fromRGBO(
                                                                        153,
                                                                        153,
                                                                        153,
                                                                        1)),
                                                          ))
                                                        ],
                                                      ),
                                                      Container(
                                                        child: Text(
                                                          '￥${goods['price']}',
                                                          style: TextStyle(
                                                              fontSize: 17),
                                                        ),
                                                      )
                                                    ],
                                                  ),
                                                  Container(
                                                    child: Text(
                                                        'x${goods['num']}'),
                                                  )
                                                ],
                                              ),
                                            ))
                                          ],
                                        ),
                                      ))
                                  .toList()),
                          Container(
                            color: Colors.white,
                            padding: EdgeInsets.only(
                                left: 10, right: 10, bottom: 10),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Container(
                                  child: Text(
                                    '共${item['total']}件商品 合计：',
                                    style: TextStyle(
                                        color:
                                            Color.fromRGBO(153, 153, 153, 1)),
                                  ),
                                ),
                                Container(
                                  child: Text(
                                    '${item['taotalPrice']}',
                                    style: TextStyle(fontSize: 17),
                                  ),
                                )
                              ],
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 10, right: 10),
                            child: Divider(
                              height: 0.3,
                            ),
                          ),
                          Container(
                            color: Colors.white,
                            padding: EdgeInsets.all(10),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                  child: Text(
                                    '2019-08-12 16:06:56',
                                    style: TextStyle(
                                        color: Color.fromRGBO(193, 193, 193, 1),
                                        fontSize: 12),
                                  ),
                                ),
                                if (item['type'] == '1')
                                  Row(
                                    children: [
                                      SizedBox(
                                        width: 90,
                                        height: 31,
                                        child: ElevatedButton(
                                          style: ElevatedButton.styleFrom(
                                              primary: Color.fromRGBO(
                                                  225, 225, 225, 1)),
                                          onPressed: () {},
                                          child: Text(
                                            '取消订单',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        ),
                                      ),
                                      SizedBox(
                                        width: 20,
                                      ),
                                      SizedBox(
                                        width: 81,
                                        height: 31,
                                        child: ElevatedButton(
                                          style: ElevatedButton.styleFrom(
                                              primary: Colors.black),
                                          onPressed: () {},
                                          child: Text(
                                            '去支付',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                if (item['type'] == '3')
                                  Row(
                                    children: [
                                      SizedBox(
                                        width: 90,
                                        height: 31,
                                        child: ElevatedButton(
                                          style: ElevatedButton.styleFrom(
                                              primary: Color.fromRGBO(
                                                  225, 225, 225, 1)),
                                          onPressed: () {
                                            Navigator.pushNamed(
                                                context, 'logistics');
                                          },
                                          child: Text(
                                            '物流跟踪',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        ),
                                      ),
                                      SizedBox(
                                        width: 20,
                                      ),
                                      SizedBox(
                                        width: 90,
                                        height: 31,
                                        child: ElevatedButton(
                                          style: ElevatedButton.styleFrom(
                                              primary: Colors.black),
                                          onPressed: () {},
                                          child: Text(
                                            '确认收货',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                if (item['type'] == '4')
                                  Row(
                                    children: [
                                      SizedBox(
                                        width: 90,
                                        height: 31,
                                        child: ElevatedButton(
                                          style: ElevatedButton.styleFrom(
                                              primary: Colors.black),
                                          onPressed: () {},
                                          child: Text(
                                            '订单评价',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                if (item['type'] == '5')
                                  Row(
                                    children: [
                                      SizedBox(
                                        width: 90,
                                        height: 31,
                                        child: ElevatedButton(
                                          style: ElevatedButton.styleFrom(
                                              primary: Color.fromRGBO(
                                                  225, 225, 225, 1)),
                                          onPressed: () {},
                                          child: Text(
                                            '删除订单',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                              ],
                            ),
                          )
                        ],
                      ),
                    ))
                .toList(),
          ),
        ));
  }
}
